<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('收款单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label >付款单编号：</label>
                                <input type="text" name="orderCode"/>
                            </li>
                            <li>
                                <label>客户名称：</label>
                                <input type="text" name="customerName"/>
                            </li>
                            <li>
                                <label>业务类型：</label>
                                <select name="capitalType" th:with="type=${@dict.getType('capital_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li>
                                <label>付款类型：</label>
                                <select name="capitalSettlementWay" th:with="type=${@dict.getType('capital_settlement_way')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>收款日期： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="bill:receivemoney:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="bill:receivemoney:edit">-->
                    <!--<i class="fa fa-edit"></i> 修改-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="bill:receivemoney:remove">-->
                    <!--<i class="fa fa-remove"></i> 删除-->
                <!--</a>-->
                <a class="btn btn-primary multiple" onclick="$.operate.audit()" shiro:hasPermission="bill:receivemoney:audit">
                    <i class="fa fa-ticket"></i> 审核
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="bill:receivemoney:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('bill:receivemoney:edit')}]];
        var removeFlag = [[${@permission.hasPermi('bill:receivemoney:remove')}]];
        var capitalTypeDatas = [[${@dict.getType('capital_type')}]];
        var capitalSettlementWayDatas = [[${@dict.getType('capital_settlement_way')}]];
        var orderStatusDatas = [[${@dict.getType('order_status')}]];
        var prefix = ctx + "bill/receivemoney";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                auditUrl: prefix + "/audit",
                modalName: "收款单",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                showFooter: true,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'orderCode',
                    title: '付款单编号'
                },
                {
                    field: 'customerName',
                    title: '客户名称'
                },
                {
                    field: 'capitalType',
                    title: '资金业务类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(capitalTypeDatas, value);
                    }
                },
                {
                    field: 'capitalSettlementWay',
                    title: '结算方式',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(capitalSettlementWayDatas, value);
                    }
                },
                {
                    field: 'orderDate',
                    title: '收款日期'
                },
                {
                    field: 'receiveBank',
                    title: '收款银行'
                },
                {
                    field: 'receiveAccount',
                    title: '收款账户'
                },
                {
                    field: 'receiveAmounts',
                    title: '收款金额',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].receiveAmounts);
                        }
                        return "总金额：" + sumBalance;
                    }
                },
                {
                    field: 'orderStatus',
                    title: '订单审核状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.orderStatus == 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/item/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: {
                    mainId: row.id
                },
                columns: [
                    {
                        field: 'id',
                        title: 'id',
                        visible: false
                    },
                    {
                        field: 'saleCode',
                        title: '销售单'
                    },
                    {
                        field: 'noReceiveAmount',
                        title: '应收金额'
                    },
                    {
                        field: 'receiveAmount',
                        title: '本次收款'
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    }
                ]
            });
        };
    </script>
</body>
</html>